using UnityEngine;

namespace VoxelGame.World
{
	public class ForceField : MonoBehaviour
	{
		[SerializeField]
		private EnergyFieldFX _fieldFx;

		[SerializeField]
		private bool _xAligned;

		[SerializeField]
		private float _heightOffset = 0.4f;

		private void OnTriggerEnter(Collider other)
		{
			if (!(other.tag == "MainCamera"))
			{
				return;
			}
			Vector3 position = other.transform.position;
			if (Physics.Raycast(position, other.transform.forward, out RaycastHit hitInfo, 3.5f) && _fieldFx.Play())
			{
				Vector3 point = hitInfo.point;
				Vector3 eulerAngles = new Vector3(90f, 0f, 0f);
				point.y += _heightOffset;
				if (_xAligned)
				{
					eulerAngles.y = 90f;
				}
				else
				{
					eulerAngles.y = 180f;
				}
				_fieldFx.transform.position = point;
				_fieldFx.transform.eulerAngles = eulerAngles;
			}
		}
	}
}
